"""
---------------------------------------------------------------------
- File: router.py
- Date: 2025/7/28
- Author: yangzhide
- Email: xxzjyzd@126.com
- Description: 系统用户表
---------------------------------------------------------------------
"""

from tortoise import fields
from app.models.base_models import IdTimestampMixin


class User(IdTimestampMixin):
    user_no = fields.CharField(max_length=20, unique=True, description="登录编号")
    password = fields.CharField(max_length=255, description="登录密码")
    user_name = fields.CharField(max_length=20, description="姓名")
    nick_name = fields.CharField(max_length=20, description="昵称")
    user_gender = fields.CharField(max_length=1, description="性别")
    user_email = fields.CharField(max_length=20, description="邮箱")
    user_phone = fields.CharField(max_length=11, description="手机")
    role_list = fields.JSONField(default=[], description="角色列表")
    status = fields.BooleanField(default=True, description="状态")
    last_login = fields.DatetimeField(null=True, description="用户最后登录时间")

    class Meta:
        """模型元数据"""

        # 数据表名
        table = "user"
        # 联合主键
        unique_together = (("user_name", "nick_name"),)
        # 表描述
        table_description = "系统用户表"
        # 索引, 可联合主键
        indexes = ("user_no",)

    def __str__(self):
        return f"{self.user_name}({self.user_no})"

    def __repr__(self):
        return f"<User {self.user_no}>"
